************************************************************
*This file builds covariates on demographics and industries*
************************************************************

**Beginning of period covariates, 1990**
use "$list/czones_list.dta", clear

merge 1:1 czone using "$clean_data_lmarket/czone1990_DemographicShares.dta", assert(3) nogenerate
merge 1:1 czone using "$clean_data_lmarket/czone1990_IndustryShares.dta", assert(3) nogenerate



*Compute additional covariates*
gen ipums_logpop_1990=ln(ipums_pop_1990)

save "$final_data_covariates/czone1990_Covariates.dta", replace

*Pre-trend covariates
**Beginning of period covariates, 1970**
use "$list/czones_list.dta", clear

merge 1:1 czone using "$clean_data_lmarket/czone1970_DemographicShares.dta", assert(3) nogenerate
merge 1:1 czone using "$clean_data_lmarket/czone1970_IndustryShares.dta", assert(3) nogenerate



*Compute additional covariates*
gen ipums_logpop_1970=ln(ipums_pop_1970)

save "$final_data_covariates/czone1970_Covariates.dta", replace

**Stacked covariates, 1990, 2000, 2008**
use "$list/czones_list.dta", clear
*merge 1990 covariates*
merge 1:1 czone using "$clean_data_lmarket/czone1990_DemographicShares.dta", assert(3) nogenerate
merge 1:1 czone using "$clean_data_lmarket/czone1990_IndustryShares.dta", assert(3) nogenerate
*merge 2000 covariates*
merge 1:1 czone using "$clean_data_lmarket/czone2000_DemographicShares.dta", assert(3) nogenerate
merge 1:1 czone using "$clean_data_lmarket/czone2000_IndustryShares.dta", assert(3) nogenerate
*merge 2008 covariates*
merge 1:1 czone using "$clean_data_lmarket/czone2008_DemographicShares.dta", assert(3) nogenerate
merge 1:1 czone using "$clean_data_lmarket/czone2008_IndustryShares.dta", assert(3) nogenerate

*obtain list of variables to reshape*
quietly: describe *_1990, varlist
local varlist = r(varlist)
local finalvar: subinstr local varlist "_1990" "_", all
reshape long `finalvar' , i(czone) j(year)
rename *_ *
gen ipums_logpop=ln(ipums_pop)
*clean*
save "$final_data_covariates/czone_Covariates.dta", replace





